﻿<%@ page contentType="text/html;charset=UTF-8" language="java"  isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="layui-row layui-col-space15">

    <div class="layui-add-line"></div>
    <fieldset class="layui-elem-field layui-field-title" style="margin:0px;">
        <legend class="layui-add-title">涉嫌食品安全处置信息</legend>
    </fieldset>

    <!--通用按钮盒子-->
    <div class="layui-col-md12" style="padding-top: 10px;padding-bottom: 10px">
        <div class="layui-btn-group demoTable">
            <a class="layui-btn layui-btn-sm" onclick="addSales()">新增+</a>
        </div>
    </div>

    <div class="layui-col-md12">
        <table class="layui-table">
            <colgroup>
                <col>
                <col >
                <col >
                <col >
                <col >
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>销货单编号</th>
                <th>客户</th>
                <th>产品名称</th>
                <th>产品标准号</th>
                <th>规格/单位</th>
                <th>联系人</th>
                <th>联系电话</th>
                <th>收货地址</th>
                <th>订单日期</th>
                <th>数量</th>
                <th lay-data="{field:'right',toolbar:'#barDemo',width:360}">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${foodSafetyDisposalList}" var="info">
                <tr>
                    <td>${info.goodsCode}</td>
                    <td>${info.customName}</td>
                    <td>${info.productName}</td>
                    <td>${info.standardNum}</td>
                    <td>${info.specifications}/${info.unit}</td>
                    <td>${info.contacts}</td>
                    <td>${info.phone}</td>
                    <td>${info.recAddress}</td>
                    <td>${info.orderDate}</td>
                    <td>${info.goodsDetailQuantity}</td>
                    <td>
                        <a class="layui-btn layui-btn-sm" onclick="editSales('${info.id}')">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-sm" onclick="deleteSales('${info.id}')">删除</a>
                    </td>
                </tr>
            </c:forEach>
            <c:if test="${empty foodSafetyDisposalList}">
                <tr>
                    <td colspan="11" style="text-align: center;">没有数据</td>
                </tr>
            </c:if>
            </tbody>
        </table>
    </div>
</div>


<script>
    layui.use(['table', 'jquery', 'layer'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var layer = layui.layer;

        var loading = layer.msg("数据加载中...");

        // 初始化表格 - 使用静态数据
        table.render({
            elem: '#demo',
            data: [], // 使用静态数据，不需要动态加载
            done: function () {
                layer.close(loading);
            }
        });

        // 绑定新增按钮事件
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            if (active[type]) {
                active[type].call(this);
            } else {
                layer.msg("未定义的操作类型: " + type);
            }
        });
    });

    // 新增函数
    function addSales() {
        console.log('新增按钮被点击，ID:', ${param.enterpriseId});
        var enterpriseId = ${param.enterpriseId};
        window.location.href = '${ctx}/enterprise/sales/add/' + enterpriseId;    }

    // 编辑函数
    function editSales(id) {
        console.log('编辑按钮被点击，ID:', id);
        window.location.href = '${ctx}/enterprise/sales/edit/' + id;
    }

    function deleteSales(id) {
        console.log('deleteSales called with id:', id); // 检查函数是否被调用
        layui.use(['layer', 'jquery'], function() {
            var layer = layui.layer;
            var $ = layui.jquery;

            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] // 按钮
            }, function(index) {
                $.post("${ctx}/enterprise/salesRemove", {id: id}, function(res) {
                    if (res === 'success') {
                        layer.msg("删除成功");
                        location.reload(); // 刷新页面
                    } else {
                        layer.msg("删除失败: " + res);
                    }
                }).fail(function(err) {
                    layer.msg("请求失败: " + err.statusText);
                });
                layer.close(index);
            }, function(index) {
                layer.close(index);
            });
        });
    }
</script>

